<?php

include_once("core/controller.php");
include_once("core/versionHandler.php");
include_once("models/maps/map.php");

/**
 * @copyright joel SIMOes
 * @package map
 *
 */
class mapAdd extends Controller{
	private $map_id;
	private $currentMap;
	private $doorPoints = array();


	public function isLegitimate(){


		return true;
	}

	public function actions(){
		$versionH = new VersionHandler("");
		$this->response->add($versionH->getMyVersion());
		
		$mapName = trim($this->request->get('mapname'));
		if (strlen($mapName) < 3)
		{
			echo "Map name to shoort";
			exit();
		}
		$maps = new Maps();
		//$mapNameEsc = mysql_escape_string($mapName);
		$result = $maps->getMapsComplex("WHERE name = '{$mapName}'", "array");
		if (count($result))
		{
			echo "Map already exist";
			exit();
		}
		$map = new Map('c');
		$map->field->name = $mapName;
		$map = null;
		$result = $maps->getMapsComplex("WHERE name = '{$mapName}'", "array");
		if (count($result))
		{
			echo "index.php?action=mapEditor&id=".$result[0]->id;
			exit();
		}
		
		
		echo "Erreur inconnue";
		exit();

	}

	public function defaultActions(){
		if (!$this->currentMap->isOk())
		{
			header("location: index.php?action=mapList");
			exit();
		}
		$this->response->setXSLT("views/login.xsl");
	}

	
}